package com.qfedu.lc.user.controller;


import com.qfedu.lc.common.config.SystemConfig;
import com.qfedu.lc.common.param.UserAdd;
import com.qfedu.lc.common.param.UserLogin;
import com.qfedu.lc.common.vo.R;
import com.qfedu.lc.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 1.用户表 前端控制器
 * </p>
 *
 * @author KK
 * @since 2024-06-05
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    public R register(HttpServletRequest request, @RequestBody UserAdd userAdd) {
        return userService.register(request, userAdd);
    }

    @RequestMapping("/loginpass")
    public R loginPass(@RequestBody UserLogin userLogin) {
        return userService.loginPass(userLogin);

    }

    @RequestMapping("/logincode")

    public R logincode(HttpServletRequest request, @RequestBody UserLogin userLogin) {
        return userService.logincode(request, userLogin);

    }

    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public R logout(HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.HEADER_TOKEN);
        return userService.logout(token);

    }

}

